from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from options import options
from time import sleep
'''
警告弹窗的常用方法
(1)switch_to_alert().accept()
(2)switch_to_alert.accept  这个比较新
'''
driver = webdriver.Chrome(options=options)
driver.get(r'https://www.baidu.com')
driver.maximize_window()
driver.implicitly_wait(30)

# 打开弹窗
ele = driver.find_element(By.ID, 's-usersetting-top')
ActionChains(driver).move_to_element(ele).perform()
sleep(3)

driver.find_element(By.LINK_TEXT,'搜索设置').click()
driver.find_element(By.LINK_TEXT,'保存设置').click()

#定位到弹窗，对弹窗进行操作
text = driver.switch_to.alert.text
print(text)
sleep(3)

#点击确定
driver.switch_to.alert.accept()
sleep(2)

driver.quit()
